

clear all

set more off 




*version 2: without topics but rainfall

global estimators xtreg



***plotting
local title_left Civil War
local title_right Armed Conflict

local left_solid_name Overall Model
local left_dash_name Within Model

local right_solid_name Overall Model
local right_dash_name Within Model

clear
use model_names
levelsof controls, local(levels) 
clear


foreach on_or_in in onset {
*foreach on_or_in in incidence {

forval p = 1 / 2 {

if `p' == 1 {
	local what civilwar
}
if `p' == 2 {
	local what armedconflict
}

foreach var in overall within {

graph drop _all

foreach j in controls {	

	foreach x in $estimators {

		display "`j'"
		display "`k'"
		display "`x'"

		clear

			*graph of war
		use output/for_roc_onlyintersection_`on_or_in'`p'

		rename modelname model
		sort model
		merge model using model_names
		sort id fpr tpr
			
		

		graph drop _all
			
		local l = 1
			
		foreach k of local levels {
		
			local doit 0
		
			if "`k'" == "fixedeffect"  {
				local nameit Fixed effect
				local doit 1
				local num 6
			}
			if "`k'" == "chadefaux"  {
				local nameit Keyword Count
				local doit 1
				local num 5
			}
			if "`k'" == "ajps"  {
				local nameit Economics and Political
				local doit 1
				local num 3
			}
			if "`k'" == "ward"  {
				local nameit Events
				local doit 1
				local num 4
			}
			if "`k'" == "pillars"  {
				local nameit Shocks and Institutions
				local doit 1
				local num 2
			}
			if "`k'" == "rain"  {
				local nameit Rainfall
				local doit 1
				local num 1
			}
			

			sum auc if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 0
			if `r(N)' > 0 & `doit' == 1 {
				local auc1 = substr(string(round(`r(max)',.01)), 1, 3)
				sum auc if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'"  & way == 1
				local auc2 = substr(string(round(`r(max)',.01)), 1, 3)

				twoway (line tpr fpr if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 0, lwidth(medthick)  lpattern(solid)  sort) ///
				(line tpr fpr if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 1, lwidth(medthick) lpattern(dash)  sort) ///
				 (line fpr fpr if what == "overall" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 1, color(gs10) lpattern(dash) sort), ///
				subtitle("`nameit'", color(black)) ytitle("") xtitle("")  xlabel(,grid) ///
				legend( order(1 "Benchmark" 2 "Topics") size(small)) ///
				plotregion(fcolor(white)) graphregion(fcolor(white))  aspectratio(1) ///	
				caption( "AUC: Benchmark `auc1', Topics `auc2'", size(medium) color(black) ring(0)  placement(se)) ///
				name(fig`num')


				local l = `l' + 1
				
			}


		}
		
		}
		
				
		grc1leg fig1 fig2 fig3 fig4 fig5 fig6 , legendfrom(fig1)  title("", color(black)  size(small)) subtitle("", color(black) size(small)) plotregion(fcolor(white)) graphregion(fcolor(white)) 

		graph export output/figE16_`var'.eps ,replace
		
	}
}



}

}






************************
*Only words and events
************************






global estimators xtreg
set more off


***plotting
local title_left Civil War
local title_right Armed Conflict

local left_solid_name Overall Model
local left_dash_name Within Model

local right_solid_name Overall Model
local right_dash_name Within Model

clear
use model_names
levelsof controls, local(levels) 
clear


foreach on_or_in in onset {
*foreach on_or_in in incidence {

forval p = 1 / 2 {

if `p' == 1 {
	local what civilwar
}
if `p' == 2 {
	local what armedconflict
}

foreach var in overall within {

graph drop _all

foreach j in controls {	

	foreach x in $estimators {

		display "`j'"
		display "`k'"
		display "`x'"

		clear

			*graph of war
		use output/for_roc_onlyintersection_`on_or_in'`p'
		*append using output/for_roc_onlyintersection_`on_or_in'`p'

		rename modelname model
		sort model
		merge model using model_names
		sort id fpr tpr
			
		replace controls = "wardshort" if model == "0"
		replace controls = "wardshort" if model == "0w"
		replace estimation = "xtreg" if model == "0"
		replace estimation = "xtreg" if model == "0w"
		replace what = "overall" if model == "0"
		replace what = "within" if model == "0w"
		replace init = "controls" if model == "0"
		replace init = "controls" if model == "0w"

		graph drop _all
			
		*local l = 1
			
		foreach k in wardshort chadefauxshort {
		
			display "`k'"
		
			local doit 0
		
			if "`k'" == "wardshort"  {
				local nameit Events Only
				local doit 1
				local num 1
			}
			if "`k'" == "chadefauxshort"  {
				local nameit Keyword Count Only
				local doit 1
				local num 2
			}
			
			*replace estimation = "xtreg"

			sum auc if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 0
			if `r(N)' > 0 & `doit' == 1 {
				local auc1 = substr(string(round(`r(max)',.01)), 1, 3)
				sum auc if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'"  & way == 1
				local auc2 = substr(string(round(`r(max)',.01)), 1, 3)

				twoway (line tpr fpr if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 0, lwidth(medthick)  lpattern(solid)  sort) ///
				(line tpr fpr if what == "`var'" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 1, lwidth(medthick) lpattern(dash)  sort) ///
				 (line fpr fpr if what == "overall" & init == "`j'" & controls == "`k'" & estimation == "`x'" & way == 1, color(gs10) lpattern(dash) sort), ///
				subtitle("`nameit'", color(black)) ytitle("") xtitle("")  xlabel(,grid) ///
				legend( order(1 "Benchmark" 2 "Topics") size(small)) ///
				plotregion(fcolor(white)) graphregion(fcolor(white))  aspectratio(1) ///	
				caption( "AUC: Benchmark `auc1', Topics `auc2'", size(medium) color(black) ring(0)  placement(se)) ///
				name(fig`num')


				local l = `l' + 1
				
			}


		}
		
		}
		
				
		grc1leg fig1 fig2 , legendfrom(fig1)  title("", color(black)  size(small)) subtitle("", color(black) size(small)) plotregion(fcolor(white)) graphregion(fcolor(white)) 

		graph export output/FigI3_`what'.eps ,replace
		
	}
}



}

}




